package com.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.CartltemDao;
import com.entity.Cartltem;

@Service
public class CartService {
	@Resource
	private CartltemDao cd;
	@Transactional
	public void updateCart(int product_id,int orders_id,Cartltem cart){
		Cartltem carts=cd.finCart(product_id, orders_id);
		if(carts==null){
			cd.addCartltem(product_id, orders_id, cart);
		}else{
			cd.pushOneCart(orders_id, carts);
		}
		
	}
	@Transactional
	public void subOneCart(int product_id,int orders_id){
		Cartltem carts=cd.finCart(product_id, orders_id);
		if(carts.getCount()>=2){
			cd.subOneCart(orders_id, carts);
		}
		
	}
	
	public List<Cartltem> finall(int orders_id){
		return cd.finall(orders_id);
	}
	@Transactional
	public void pushcart(int orders_id){
		List<Cartltem> carts=cd.finall(orders_id);
		if(carts!=null){
			cd.updateCart(carts);
		}
	}
}
